<?php

namespace App\Http\Response;

use App\Exceptions\ExceptionApi;
use App\Models\User;
use App\Services\Uri;

class UserResponse
{
    public static function toArray(User $model, $isNew=0){
        if(!in_array($isNew,[0,1])){
            throw new ExceptionApi('isNew 取值错误',500);
        }
        return [
            'memid' => $model->id,
            'id' => $model->id,
            'mobile' => $model->mobile,
            'nickname' => $model->nickname,
            'avatar' => Uri::createImageUrl($model->image),
            'token' => $model->getApiToken(),
            'isnew' => $isNew
        ];
    }

}
